﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Microsoft.Practices.EnterpriseLibrary.Caching;

namespace Titan.Caching
{
    public static class EnterpriseCache
    {
        private static ReaderWriterLock _lock = new ReaderWriterLock();

        private static Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager cachemanager = (Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager)CacheFactory.GetCacheManager();

        public static void Set<T>(string key, T objectToCache)
        {
            cachemanager.Add(key, objectToCache);
        }

        public static T Get<T>(string key)
        {
            T cachedObject = default(T);

            if (cachemanager.Contains(key))
            {
                cachedObject = (T)cachemanager.GetData(key);
            }
            return cachedObject;
        }

        public static void Clear()
        {
            cachemanager.Flush();
        }

        public static bool Has(string key)
        {
            return cachemanager.Contains(key);
        }
    }

}
